package cn.fivestars.springcloud.stream.service.impl;

import cn.fivestars.springcloud.stream.kafka.OutputBinder;
import cn.fivestars.springcloud.stream.service.IMessageProvider;
import cn.hutool.core.lang.UUID;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;

/**
 * @author liangchenzhou1024@163.com
 * @date 2021/3/14
 */
@EnableBinding(OutputBinder.class) // 定义消息的推送管道
@Slf4j
public class MessageProviderImpl implements IMessageProvider {

    @Resource
    private OutputBinder binder;

    @Override
    public String send() {
        String serial = UUID.fastUUID().toString();
        binder.output().send(MessageBuilder.withPayload(serial).build());
        log.info("send message:serial={}", serial);

        return serial;
    }
}
